package com.css.fxfzaqbz.modules.data.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.data.entity.ReportTemplateEntity;
import com.css.fxfzaqbz.modules.data.queryParams.ReportTemplateEntityQueryParams;
import com.css.fxfzaqbz.modules.data.service.ReportTemplateService;
import com.css.fxfzaqbz.modules.data.vo.CheckReportVO;
import com.css.fxfzaqbz.modules.data.vo.ReportTemplateVO;
import com.css.fxfzaqbz.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author y1fan
 * @create 2022-11-04 15:20
 *
 * 小报告 的一些接口
 */
@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class ReportTemplateController {


    @Resource
    private ReportTemplateService reportTemplateService;

    /*
    * 添加报告接口
    *
    * */
    @PostMapping("/saveReportTemplate")
    public RestResponse saveReportTemplate(@RequestBody List<ReportTemplateVO> reportTemplateVOS) {
        RestResponse restResponse = null;
        try {
            reportTemplateService.saveReportTemplate(reportTemplateVOS);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("新增报告模板失败", e);
            restResponse = RestResponse.fail("新增报告模板失败!");
        }
        return restResponse;
    }
    /*
     * 校验报告是否重复接口
     *
     * */
    @PostMapping("/checkReportTemplate")
    public RestResponse checkReportTemplate(@RequestBody CheckReportVO checkReportVO) {
        RestResponse restResponse = null;
        try {
         Boolean flag= reportTemplateService.checkReportTemplate(checkReportVO);
            restResponse = RestResponse.succeed(flag);
        } catch (Exception e) {
            log.error("校验报告模板失败", e);
            restResponse = RestResponse.fail("校验报告模板失败!");
        }
        return restResponse;
    }

    /*
    * 查询报告列表接口
    * */
    @GetMapping("/getAllReportTemplate")
    public RestResponse getAllReportTemplate(HttpServletRequest request, ReportTemplateEntityQueryParams reportTemplateEntityQueryParams) {
        RestResponse restResponse = null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            reportTemplateEntityQueryParams.setCurPage(curPage);
            reportTemplateEntityQueryParams.setPageSize(pageSize);
            Map<String,Object> map = reportTemplateService.getAllReportTemplate(reportTemplateEntityQueryParams);
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            log.error("查询报告模板信息失败!", e);
            restResponse = RestResponse.fail("查询报告模板信息失败");
        }
        return restResponse;
    }


    /*
     * 查询各类报告模板  0 1  2  三类
     * */
    @GetMapping("/getList/{rtType}")
    public RestResponse getList(@PathVariable("rtType")String rtType) {
        RestResponse restResponse = null;
        try {

            List<ReportTemplateEntity> reportTemplateEntities= reportTemplateService.getList(rtType);
            restResponse = RestResponse.succeed(reportTemplateEntities);
        } catch (Exception e) {
            log.error("查询报告模板信息失败!", e);
            restResponse = RestResponse.fail("查询报告模板信息失败");
        }
        return restResponse;
    }


    /*
    *
    * 删除报告接口
    * */
    @PostMapping("/delReportTemplate/{ids}")
    public RestResponse delReportTemplate(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            reportTemplateService.delReportTemplate(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除报告模板失败!", e);
            restResponse = RestResponse.fail("删除报告模板失败!");
        }
        return restResponse;
    }


}
